package top.dancun.eascourse.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import top.dancun.common.utils.DataUtils;
import top.dancun.eascourse.entity.ScoresEntity;
import top.dancun.eascourse.service.ScoresService;
import top.dancun.common.utils.PageUtils;
import top.dancun.common.utils.R;



/**
 * 成绩
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-11-05 10:12:23
 */
@RestController
@RequestMapping("/scores")
public class ScoresController extends AbstractController{
    @Autowired
    private ScoresService scoresService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("eascourse:scores:list")
    public R list(@RequestBody Map<String, Object> params){
        Map<String ,String > data = DataUtils.mapAddNoEmpty(params,ScoresEntity.class);
        PageUtils page = scoresService.queryPage(params,data);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/getmyscores")
    public R GetMyScores(@RequestBody Map<String, Object> params){
        params.put("studentId",getUserId());
        Map<String ,String > data = DataUtils.mapAddNoEmpty(params,ScoresEntity.class);
        PageUtils page = scoresService.queryPage(params,data);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    @RequiresPermissions("eascourse:scores:info")
    public R info(@RequestBody ScoresEntity scoresParams){
		ScoresEntity scores = scoresService.getByTidAndCourseId(scoresParams);

        return R.ok().put("scores", scores);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("eascourse:scores:save")
    public R save(@RequestBody ScoresEntity scores){
		scoresService.save(scores);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("eascourse:scores:update")
    public R update(@RequestBody ScoresEntity scores){
		scoresService.updateById(scores);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("eascourse:scores:delete")
    public R delete(@RequestBody Long[] ids){
		scoresService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
